﻿using DevHelp;
using DevTool.Baidu;
using DevTool.Operation;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;

namespace DevTool
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;//设置该属性 为false
            InitializeComponent();

            textBox_field.Text = INIhelp.GetValue("字段名");
            textBox_en.Text = INIhelp.GetValue("字段名2");
            textBox_fields.Text = INIhelp.GetValue("字段名3");
            textBox12.Text = INIhelp.GetValue("名字");
            textBox13.Text = INIhelp.GetValue("岗位");
            textBox_appid.Text = INIhelp.GetValue("baiduappid");
            textBox_appsk.Text = INIhelp.GetValue("baiduappsk");
            if (!string.IsNullOrWhiteSpace(INIhelp.GetValue("留言板")))
            {
                textBox_MessageBoard.Text = INIhelp.GetValue("留言板");
            }

            button6_Click(null, null);
            button_pattern.Text = "开发模式";
            IntroduceOperation.SwitchStyle(button_pattern.Text, tabControl_tool);
        }

        private void button_translate_Click(object sender, EventArgs e)
        {
            textBox_en.Text = "";
            var num1 = Task.Factory.StartNew(() =>
            {
                var btcst = Baidu_Trans_C_Sharp.Trans(textBox_appid.Text, textBox_appsk.Text, textBox_field.Text);

                var jArray = JsonConvert.DeserializeObject<bdfy>(btcst);
                foreach (var item in jArray.trans_result)
                {
                    textBox_en.Text += item.dst + "\r\n";
                }
                //textBox_en.Text = GenFieldOperation.Translate(textBox_field.Text);
            }, TaskCreationOptions.LongRunning);
        }


        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox_en.Text.Trim() == "" || textBox_en.Text.Trim().Length == 0)
            {
                return;
            }
            List<string> wes = new List<string>();
            var we = textBox_en.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
            foreach (var item in we)
            {
                string jiaGongStr = TagConvertTool(item, comboBox1.Text);
                wes.Add(jiaGongStr);
            }
            textBox_fields.Text = string.Join("\r\n", wes);
        }

        private string TagConvertTool(string item, string type)
        {
            var jiaGongStr = item.Replace(" ", "_")
                    .Replace("(", "").Replace(")", "")
                    .Replace("（", "").Replace("）", "")
                    .Replace("/", "").Replace("__", "_");
            if (type == "下划线")
            {
                string xhxStrs = jiaGongStr.ToLower();
                jiaGongStr = xhxStrs;
            }
            if (type == "大驼峰")
            {
                string xhxStrs = jiaGongStr;
                string dtfStr = "";
                foreach (var xxitem in xhxStrs.Split('_'))
                {
                    if (!string.IsNullOrWhiteSpace(xxitem))
                    {
                        dtfStr += $"{xxitem[0]}".ToUpper() + xxitem.Substring(1);
                    }
                };
                jiaGongStr = dtfStr;
            }
            if (type == "小驼峰")
            {
                string xhxStrs = jiaGongStr;
                string dtfStr = "";
                string xtfStr = "";
                foreach (var xxitem in xhxStrs.Split('_'))
                {
                    if (!string.IsNullOrWhiteSpace(xxitem))
                    {
                        dtfStr += $"{xxitem[0]}".ToUpper() + xxitem.Substring(1);
                    }
                };
                if (!string.IsNullOrWhiteSpace(dtfStr))
                {
                    xtfStr = $"{dtfStr[0]}".ToLower() + dtfStr.Substring(1);
                }
                jiaGongStr = xtfStr;
            }

            return jiaGongStr;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (textBox_en.Text.Trim() == "" || textBox_en.Text.Trim().Length == 0)
            {
                return;
            }
            List<string> wes = new List<string>();
            var we = textBox_en.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
            foreach (var item in we)
            {
                string jiaGongStr = TagConvertTool(item, comboBox1.Text);
                wes.Add(jiaGongStr);
            }
            textBox_fields.Text = string.Join("\r\n", wes);
        }


        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            INIhelp.SetValue("字段名", textBox_field.Text);

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            INIhelp.SetValue("字段名2", textBox_en.Text);
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            INIhelp.SetValue("字段名3", textBox_fields.Text);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            var zw = textBox_field.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
            var yw = textBox_fields.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();

            var tableName = textBox_gen_tablename.Text;
            textBox_mysql_result.Text = textBox_mysql_model.Text.Replace("sys_demo", tableName).Replace("`demo_id", $"`{tableName}_id");
            for (int i = 0; i < zw.Count(); i++)
            {
                textBox_mysql_result.Text += $"\r\nALTER TABLE `{tableName}` ADD COLUMN `{yw[i]}` VARCHAR(50) NULL DEFAULT NULL COMMENT '{zw[i]}';";
            }
        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {
            var zw = textBox_field.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).Where(a => !string.IsNullOrWhiteSpace(a)).ToList();
            var yw = textBox_fields.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).Where(a => !string.IsNullOrWhiteSpace(a)).ToList();
            var tableName = textBox_gen_tablename.Text;
            textBox_mysql_result.Text = textBox_mysql_model.Text.Replace("sys_demo", tableName).Replace("`demo_id", $"`{tableName}_id");
            for (int i = 0; i < zw.Count(); i++)
            {
                textBox_mysql_result.Text += $"\r\nALTER TABLE `{tableName}` ADD COLUMN `{yw[i]}` VARCHAR(50) NULL DEFAULT NULL COMMENT '{zw[i]}';";
            }

        }

        private void button5_Click(object sender, EventArgs e)
        {
            label4.Text = "状态：已保存";
            lock (this)
            {
                if (true)
                {
                    var t10sp = textBox10.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
                    logs = t10sp;
                    var tableName = "_dev_logs";
                    SQLiteUtlis s = Create_table(tableName);

                    var date = DateTime.Parse(dateTimePicker1.Text).ToString("yyyy-MM-dd");

                    s.ExecuteNonQuery($"DELETE FROM \"{tableName}\" WHERE  \"log_date\"='{date}'");
                    for (int i = 0; i < logs.Count(); i++)
                    {
                        s.ExecuteNonQuery($"insert into {tableName} (log_date,log_id,log_text) values ('{date}','{i}','{logs[i]}')");
                    }
                }


                if (true)
                {
                    var t11sp = textBox11.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
                    logs_next = t11sp;
                    var tableName = "_dev_logs_next";
                    SQLiteUtlis s = Create_table(tableName);

                    var date = DateTime.Parse(dateTimePicker1.Text).ToString("yyyy-MM-dd");

                    s.ExecuteNonQuery($"DELETE FROM \"{tableName}\" WHERE  \"log_date\"='{date}'");
                    for (int i = 0; i < logs_next.Count(); i++)
                    {
                        s.ExecuteNonQuery($"insert into {tableName} (log_date,log_id,log_text) values ('{date}','{i}','{logs_next[i]}')");
                    }
                }
            }
        }

        int isnotRe = 0;


        private void label4_Click(object sender, EventArgs e)
        {
            if (textBox7.Text == "读取工作日志")
            {
                string text = System.IO.File.ReadAllText(@"C:\Users\dao\Desktop\1\日志.txt");
                var alllog = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
                bool isJL1 = false;
                bool isJL2 = false;
                int isBC = 0;
                foreach (var item in alllog)
                {
                    label4.Text = "状态：已保存";
                    if (item.Contains("年"))
                        if (item.Contains("月"))
                            if (item.Contains("日"))
                            {
                                isBC++;
                            }

                    if (isBC > 1)
                    {
                        if (true)
                        {
                            var t10sp = textBox10.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
                            logs = t10sp;
                            var tableName = "_dev_logs";
                            SQLiteUtlis s = Create_table(tableName);
                            var date = DateTime.Parse(dateTimePicker1.Text).ToString("yyyy-MM-dd");

                            s.ExecuteNonQuery($"DELETE FROM \"{tableName}\" WHERE  \"log_date\"='{date}'");
                            for (int i = 0; i < logs.Count(); i++)
                            {
                                s.ExecuteNonQuery($"insert into {tableName} (log_date,log_id,log_text) values ('{date}','{i}','{logs[i]}')");
                            }
                        }


                        if (true)
                        {
                            var t11sp = textBox11.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
                            logs_next = t11sp;
                            var tableName = "_dev_logs_next";
                            SQLiteUtlis s = Create_table(tableName);

                            var date = DateTime.Parse(dateTimePicker1.Text).ToString("yyyy-MM-dd");

                            s.ExecuteNonQuery($"DELETE FROM \"{tableName}\" WHERE  \"log_date\"='{date}'");
                            for (int i = 0; i < logs_next.Count(); i++)
                            {
                                s.ExecuteNonQuery($"insert into {tableName} (log_date,log_id,log_text) values ('{date}','{i}','{logs_next[i]}')");
                            }
                        }
                        textBox10.Text = "";
                        textBox11.Text = "";
                        isBC = 1;
                    }


                    if (item.Contains("年"))
                        if (item.Contains("月"))
                            if (item.Contains("日"))
                            {
                                //开始记录存储
                                var dateC = item.Replace("时间：", "").Substring(0, 10);
                                var date = dateC.Replace("年", "-").Replace("月", "-").Replace("日", "");
                                label4.Text = "状态：已保存";
                                dateTimePicker1.Text = date;
                                isJL2 = false;
                            }
                    if (item.Contains("2.实施人员问题处理"))
                    {
                        isJL1 = false;
                    }
                    if (isJL1 && !string.IsNullOrWhiteSpace(item))
                    {
                        textBox10.Text += item + "\r\n";
                    }
                    if (item.Contains("1.产品研发需求"))
                    {
                        isJL1 = true;
                    }

                    if (isJL2 && !string.IsNullOrWhiteSpace(item))
                    {
                        textBox11.Text += item + "\r\n";
                    }
                    if (item.Contains("明日计划"))
                    {
                        isJL2 = true;
                    }

                }
                return;
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            label4.Text = "状态：已保存";
            if (true)
            {
                var tableName = "_dev_logs";
                SQLiteUtlis s = Create_table(tableName);
                //var date = DateTime.Parse(dateTimePicker1.Text).ToString("yyyy-MM-dd");
                var date = dateTimePicker1.Value.ToString("yyyy-MM-dd");
                var table = s.ExecuteQuery($"select * from {tableName} WHERE  \"log_date\"='{date}'");
                logs.Clear();
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    logs.Add(table.Rows[i]["log_text"].ToString());
                }
                if (textBox10.Text != String.Join("\r\n", logs))
                {
                    isnotRe++;
                    isnotRe++;
                    textBox10.Text = String.Join("\r\n", logs);
                }
            }

            if (true)
            {
                var tableName = "_dev_logs_next";
                SQLiteUtlis s = Create_table(tableName);
                //var date = DateTime.Parse(dateTimePicker1.Text).ToString("yyyy-MM-dd");
                var date = dateTimePicker1.Value.ToString("yyyy-MM-dd");
                var table = s.ExecuteQuery($"select * from {tableName} WHERE  \"log_date\"='{date}'");
                logs_next.Clear();
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    logs_next.Add(table.Rows[i]["log_text"].ToString());
                }
                if (textBox11.Text != String.Join("\r\n", logs_next))
                {
                    isnotRe++;
                    isnotRe++;
                    textBox11.Text = String.Join("\r\n", logs_next);
                }
            }
            ReLog();
        }

        private void ReLog()
        {
            if (true)
            {
                textBox_loginfo.Text = "";
                //var date = DateTime.Parse(dateTimePicker1.Text).ToString("yyyy-MM-dd");
                var date = dateTimePicker1.Value.ToString("yyyy-MM-dd");
                var dep = "产品研发部";
                var name = textBox12.Text;
                var post = textBox13.Text;
                textBox_loginfo.Text += $"日期：{date}\r\n";
                textBox_loginfo.Text += $"部门：{dep}\r\n";
                textBox_loginfo.Text += $"姓名：{name}\r\n";
                textBox_loginfo.Text += $"岗位：{post}\r\n";

                textBox_loginfo.Text += $"一、 工作内容\r\n";
                int jishu = 0;
                foreach (var log in logs)
                {
                    if (string.IsNullOrWhiteSpace(log))
                    {
                        continue;
                    }
                    if (log.Length < 2)
                    {
                        continue;
                    }
                    jishu++;
                    textBox_loginfo.Text += $"{jishu}、{log}\r\n";
                };
                textBox_loginfo.Text += $"二、下个工作日：工作计划\r\n";
                jishu = 0;
                foreach (var log in logs_next)
                {
                    if (string.IsNullOrWhiteSpace(log))
                    {
                        continue;
                    }
                    if (log.Length < 2)
                    {
                        continue;
                    }
                    jishu++;
                    textBox_loginfo.Text += $"{jishu}、{log}\r\n";
                }



            }
        }

        List<string> logs = new List<string>();
        List<string> logs_next = new List<string>();

        private void textBox10_TextChanged(object sender, EventArgs e)
        {
            if (isnotRe > 0)
            {
                isnotRe--;
            }
            if (isnotRe <= 0)
            {
                label4.Text = "状态：未保存";
                isnotRe = 0;
            }
            lock (this)
            {
                var t10sp = textBox10.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
                logs = t10sp;
                ReLog();
            }
        }

        private void textBox11_TextChanged(object sender, EventArgs e)
        {
            if (isnotRe > 0)
            {
                isnotRe--;
            }
            if (isnotRe <= 0)
            {
                label4.Text = "状态：未保存";
                isnotRe = 0;
            }
            lock (this)
            {
                var t11sp = textBox11.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
                logs_next = t11sp;
                ReLog();
            }
        }
        private static SQLiteUtlis Create_table(string tableName)
        {
            //创建一个表
            string[] colNames = new string[] { "log_date", "log_id", "log_text" };
            string[] colTypes = new string[] { "TEXT", "TEXT", "TEXT" };
            string queryString = SQLiteUtlis.CteateTableSql(tableName, colNames, colTypes);
            SQLiteUtlis s = new SQLiteUtlis();
            s.ExecuteNonQuery(queryString);
            return s;
        }

        private void textBox7_TextChanged(object sender, EventArgs e)
        {
            lock (this)
            {
                var tableName = "_dev_logs";
                var info = textBox7.Text;
                SQLiteUtlis s = Create_table(tableName);
                var table = s.ExecuteQuery($"select * from {tableName} WHERE  \"log_text\" like '%{info}%' LIMIT 3000 ");
                List<string> ls_logs = new List<string>();
                //for (int i = 0; i < table.Rows.Count; i++)
                //{
                //    ls_logs.Add(table.Rows[i]["log_text"].ToString());
                //}
                for (int i = table.Rows.Count; i > 0; i--)
                {
                    ls_logs.Add(table.Rows[i - 1]["log_text"].ToString());
                }

                textBox9.Text = String.Join("\r\n", ls_logs.Distinct().ToList().Take(20).ToList());
            }
        }

        private void textBox12_TextChanged(object sender, EventArgs e)
        {
            lock (this)
            {
                INIhelp.SetValue("名字", textBox12.Text);
            }
        }

        private void textBox13_TextChanged(object sender, EventArgs e)
        {
            lock (this)
            {
                INIhelp.SetValue("岗位", textBox13.Text);
            }
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox8_TextChanged(object sender, EventArgs e)
        {

        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void tabPage2_Click(object sender, EventArgs e)
        {

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }



        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void tabPage3_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox9_TextChanged(object sender, EventArgs e)
        {

        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {

            if (label4.Text == "状态：未保存")
            {
                DialogResult result = MessageBox.Show("继续操作？还有日志未保存！", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result == DialogResult.OK)
                {
                    button6_Click(sender, e);
                }
                else
                {

                }
            }
            else
            {

                button6_Click(sender, e);
            }
        }

        private void tabPage4_Click(object sender, EventArgs e)
        {

        }

        private void button7_Click(object sender, EventArgs e)
        {
            List<string> logsZJH = new List<string>();
            var we = DateTime.Parse(dateTimePicker3.Text) - DateTime.Parse(dateTimePicker2.Text);
            var date2 = DateTime.Parse(dateTimePicker2.Text).ToString("yyyy-MM-dd");
            var date3 = DateTime.Parse(dateTimePicker3.Text).ToString("yyyy-MM-dd");
            for (int i = 0; i < 7; i++)
            {
                var startDate = DateTime.Parse(dateTimePicker2.Text).AddDays(i).ToString("yyyy-MM-dd");

                var tableName = "_dev_logs";
                SQLiteUtlis s = Create_table(tableName);
                var table = s.ExecuteQuery($"select * from {tableName} WHERE  \"log_date\"='{startDate}'");

                for (int j = 0; j < table.Rows.Count; j++)
                {
                    logsZJH.Add(table.Rows[j]["log_text"].ToString());
                }
            }
            if (true)
            {
                textBox19.Text = "";
                var dep = "产品研发部";
                var name = textBox12.Text;
                var post = textBox13.Text;
                textBox19.Text += $"日期：{date3}\r\n";
                textBox19.Text += $"部门：{dep}\r\n";
                textBox19.Text += $"姓名：{name}\r\n";
                textBox19.Text += $"岗位：{post}\r\n";

                textBox19.Text += $"一、 上周工作总结\r\n";
                int jishu = 0;
                foreach (var log in logsZJH)
                {
                    if (string.IsNullOrWhiteSpace(log))
                    {
                        continue;
                    }
                    if (log.Length < 2)
                    {
                        continue;
                    }
                    jishu++;
                    textBox19.Text += $"{jishu}、{log}\r\n";
                };
                textBox19.Text += $"二、本周工作安排\r\n";
            }
        }

        private void TextFactoryTextBoxSource_TextChanged(object sender, EventArgs e)
        {
            if (true)
            {
                //Factory
                if (checkBox_noSpace.Checked)
                {
                    TextFactoryTextBoxSource.Text = TextFactoryTextBoxSource.Text.Replace(" ", "");
                }
                if (checkBox_noSpaceLine.Checked)
                {
                }

            }

            switch (textFactoryBSStr)
            {
                case "重新定位标识":
                    TextFactoryTextBoxTarget.Text = TextFactoryOperation.TextChangedCXDW(TextFactoryTextBoxSource.Text, textBox_cxdwbs.Text);
                    break;
                case "去除定位标识":
                    TextFactoryTextBoxTarget.Text = TextFactoryOperation.TextChangedQCDW(TextFactoryTextBoxSource.Text, textBox_cxdwbs.Text);
                    break;
                case "换行加定位标识":
                    TextFactoryTextBoxTarget.Text = TextFactoryOperation.TextChangedHHJDW(TextFactoryTextBoxSource.Text, textBox_cxdwbs.Text);
                    break;
                default:
                    TextFactoryTextBoxTarget.Text = TextFactoryTextBoxSource.Text;
                    break;
            }
        }


        private void textBox23_TextChanged(object sender, EventArgs e)
        {
            var t23sp = textBox_mysql_savetable1.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
            if (t23sp != null && t23sp.Count() > 0)
            {
                textBox_mysql_savetable2.Text = "";
                if (checkBox1.Checked)
                {
                    textBox_mysql_savetable2.Text = $"DROP TABLE `{t23sp[0].Replace("CREATE TABLE `", "").Replace("` (", "")}_old`;";
                }
                for (int i = 0; i < t23sp.Count(); i++)
                {
                    var strInfo = t23sp[i].Trim();
                    if (strInfo.Contains("COMMENT="))
                    {
                        strInfo = strInfo.Remove(strInfo.Length - 1) + "_存储表'";
                    }
                    if (strInfo.Contains("CREATE TABLE"))
                    {
                        strInfo = strInfo.Replace("` (", "_old` (");
                    }
                    if (strInfo.Contains("AUTO_INCREMENT "))
                    {
                        strInfo = strInfo.Replace("AUTO_INCREMENT ", "");
                    }
                    textBox_mysql_savetable2.Text += $"{strInfo}\r\n";
                }
            }
        }

        private void button13_Click(object sender, EventArgs e)
        {
            if (false)
            {
                if (textBox_en.Text.Trim() == "" || textBox_en.Text.Trim().Length == 0)
                {
                    return;
                }
                List<string> wes = new List<string>();
                var we1 = textBox_field.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
                var we2 = textBox_en.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
                var we3 = textBox_fields.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
                foreach (var item in we3)
                {
                    textBox25.Text = item;
                }
                textBox_fields.Text = string.Join("\r\n", wes);
            }
            textBox27.Text = "";
            if (true)
            {
                var we1 = textBox25.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
                foreach (var item in we1)
                {
                    string model = textBox26.Text;
                    Dictionary<string, string> dict = new Dictionary<string, string>();
                    var ii = item.Split(new string[] { "\t" }, StringSplitOptions.None).ToList();
                    for (int i = 0; i < ii.Count; i++)
                    {
                        string item2 = ii[i];
                        dict.Add("{{i" + i + "}}", item2);
                    }
                    foreach (var dd in dict)
                    {
                        model = model.Replace(dd.Key, dd.Value);
                    }
                    textBox27.Text += model + "\r\n";
                }
            }

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (label4.Text == "状态：未保存")
            {
                DialogResult result = MessageBox.Show("你确定要退出程序吗？还有日志未保存！", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result == DialogResult.OK)
                {
                    System.Environment.Exit(0);
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        #region 切换

        private void button_pattern_Click(object sender, EventArgs e)
        {
            if (button_pattern.Text == "工作模式")
            {
                button_pattern.Text = "开发模式";
            }
            else
            {
                button_pattern.Text = "工作模式";
            }
            IntroduceOperation.SwitchStyle(button_pattern.Text, tabControl_tool);
        }

        #endregion

        private void tabPage_textFactory_Click(object sender, EventArgs e)
        {

        }

        private void timer_maintain_Tick(object sender, EventArgs e)
        {
            if (true)
            {
                label_time.Text = $"时间：{DateTime.Now.ToString()}";
            }
        }

        private void tabPage_js_Click(object sender, EventArgs e)
        {

        }

        private void textBox_appid_TextChanged(object sender, EventArgs e)
        {
            INIhelp.SetValue("baiduappid", textBox_appid.Text);
        }

        private void textBox_appsk_TextChanged(object sender, EventArgs e)
        {
            INIhelp.SetValue("baiduappsk", textBox_appsk.Text);
        }

        private void textBox_MessageBoard_TextChanged_1(object sender, EventArgs e)
        {
            INIhelp.SetValue("留言板", textBox_MessageBoard.Text);
        }
        #region 标识设置
        private string textFactoryBSStr = "";
        private void radioButton_cxdwbs_CheckedChanged(object sender, EventArgs e)
        {
            textFactoryBSStr = ((System.Windows.Forms.RadioButton)sender).Text;
            string text = "重新定位标识：将 1、3、4、这种乱序的排序成有序的 1、2、3、";
            textBox_bs_tsb.Text = text.Replace("、", textBox_cxdwbs.Text);
            TextFactoryTextBoxSource_TextChanged(sender, e);
        }

        private void radioButton_qcdwbs_CheckedChanged(object sender, EventArgs e)
        {
            textFactoryBSStr = ((System.Windows.Forms.RadioButton)sender).Text;
            string text = "去除定位标识：将 1、2、3、这种排序的 去除前面的 1、2、3、";
            textBox_bs_tsb.Text = text.Replace("、", textBox_qcdwbs.Text);
            TextFactoryTextBoxSource_TextChanged(sender, e);
        }

        private void radioButton_hhjdwbs_CheckedChanged(object sender, EventArgs e)
        {
            textFactoryBSStr = ((System.Windows.Forms.RadioButton)sender).Text;
            string text = "换行加定位标识：将每一行都加上定位排序，1、2、3、";
            textBox_bs_tsb.Text = text.Replace("、", textBox_hhjdwbs.Text);
            TextFactoryTextBoxSource_TextChanged(sender, e);
        }

        private void radioButton_none_CheckedChanged(object sender, EventArgs e)
        {
            textFactoryBSStr = ((System.Windows.Forms.RadioButton)sender).Text;
            textBox_bs_tsb.Text = "你可以选择下面几种方案来对标识进行处理";
            TextFactoryTextBoxSource_TextChanged(sender, e);
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void checkBox_noSpace_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void checkBox_noSpaceLine_CheckedChanged(object sender, EventArgs e)
        {

        }

        #endregion

        #region 正则表达式

        /// <summary>
        /// 正则表达式文本源变化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void textBox_zz_source_TextChanged(object sender, EventArgs e)
        {
            ZZRun();
        }

        /// <summary>
        /// 正则表达式规则变化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void textBox_zz_pattern_TextChanged(object sender, EventArgs e)
        {
            ZZRun();
        }

        /// <summary>
        /// 正则表达式执行
        /// </summary>
        private void ZZRun()
        {
            if (!string.IsNullOrWhiteSpace(textBox_zz_pattern.Text))
            {
                textBox_zz_result.Text = "";
                StringBuilder stringBuilder = new StringBuilder();
                string input = textBox_zz_source.Text;
                string pattern = textBox_zz_pattern.Text;
                var result = Regex.Matches(input, pattern);
                stringBuilder.Append($"找到匹配 ： {result.Count} 个\r\n");
                foreach (Match match in result)
                {
                    stringBuilder.Append(match.Value.ToString() + "\r\n");
                }
                textBox_zz_result.Text = stringBuilder.ToString();
            }
        }
        #endregion

    }
}
